<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script>
    <link rel="stylesheet" href="/css/ui.css"/>
</head>
<body>

<div class="weui-form">
    <div class="weui-form__text-area">
        <h2 class="weui-form__title">注册</h2>
    </div>
    <div class="weui-form__control-area">
        <div class="weui-cells__group weui-cells__group_form">
            <div class="weui-cells weui-cells_form">
                <label for="email" class="weui-cell weui-cell_active">
                    <div class="weui-cell__hd"><span class="weui-label">邮箱</span></div>
                    <div class="weui-cell__bd">
                        <input id="email" type="text" class="weui-input" placeholder="填写本人邮箱"/>
                    </div>
                </label>
                <label for="password" class="weui-cell weui-cell_active">
                    <div class="weui-cell__hd"><span class="weui-label">密码</span></div>
                    <div class="weui-cell__bd">
                        <input id="password" type="password" class="weui-input" placeholder="登录密码"/>
                    </div>
                </label>
                <label for="studentNo" class="weui-cell weui-cell_active">
                    <div class="weui-cell__hd"><span class="weui-label">学号</span></div>
                    <div class="weui-cell__bd">
                        <input id="studentNo" type="text" class="weui-input" placeholder="填写本人学号"/>
                    </div>
                </label>
                <label for="name" class="weui-cell weui-cell_active">
                    <div class="weui-cell__hd"><span class="weui-label">姓名</span></div>
                    <div class="weui-cell__bd">
                        <input id="name" type="text" class="weui-input" placeholder="填写本人姓名"/>
                    </div>
                </label>
            </div>
        </div>
    </div>
    <label class="weui-cell weui-cell_active weui-check__label" for="x11">
        <div class="weui-cell__bd">
            <p>男</p>
        </div>
        <div class="weui-cell__ft">
            <input type="radio" name="gender" id="x11" value="男"/>
        </div>
    </label>
    <label class="weui-cell weui-cell_active weui-check__label" for="x12">
        <div class="weui-cell__bd">
            <p>女</p>
        </div>
        <div class="weui-cell__ft">
            <input type="radio" name="gender" id="x12" value="女" checked="checked"/>
        </div>
    </label>
    <div class="weui-form__tips-area">
        <p class="weui-form__tips" id="result">
        </p>
    </div>
    <div class="weui-form__opr-area">
        <a role="button" id="btn1" class="weui-btn weui-btn_primary">确定</a>
    </div>
</div>

</body>
<script type="text/javascript">
    $(document).ready(function () {
        $("#btn1").click(function () {
            let email = $("#email").val();
            let pwd = $("#password").val();
            let studentNo = $("#studentNo").val();
            let name = $("#name").val();
            let gender = $("input[name='gender']:checked").val();

            let paramData = {
                "email": email,
                "passWord": pwd,
                "userInfo": {
                    "studentNo": studentNo,
                    "name": name,
                    "gender": gender
                }
            }
            console.log(paramData);
            $.ajax({
                type: 'post',
                url: "http://59.110.168.33:8080/register",
                contentType: 'application/json;charset=utf-8',
                dataType: 'json',
                data: JSON.stringify(paramData),
                success: function (data) {
                    console.log(data);
                    if (data.code === 200) {
                        alert("注册成功");
                        location.href = "http://59.110.168.33:8080/login";
                    } else {
                        $("#result").text(data.msg);
                    }
                },
                error: function () {
                    console.log()
                    $("#result").text("网络错误");
                }
            });
        });
    });
</script>
</html>
